package com.lightbend.akka.encapsulate

import akka.actor.Actor
import akka.actor.Actor._
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Sink, Source}

import scala.concurrent.ExecutionContextExecutor

class PrintSomeNumbers(implicit materializer: ActorMaterializer) extends Actor {
  private implicit val executionContext: ExecutionContextExecutor = context.system.dispatcher

  Source(1 to 10)
    .map(self ! _)
    .runWith(Sink.ignore)
    .map(_ => self ! "done")

  override def receive: Receive = {
    case x: Int =>
      println(s"==> Encapsulate $x")
    case "done" =>
      println("Done")
      context.stop(self)
  }
}